﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data;
using ElingOA6_Admin_DSJCJ.Common;
using DevExpress.Web.ASPxUploadControl;
using DevExpress.Web.Mvc;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;

namespace ElingOA6_Admin_DSJCJ.Areas.Admin.Controllers
{
    /// <summary>
    /// 工作周日志
    /// </summary>
    [OutputCache(Duration = 0, VaryByParam = "none")]
    public class WeekPlanController : AdminBaseController
    {
        /// <summary>
        /// 登录人员逻辑类
        /// </summary>
        private BLL.PrvUser prvUserBLL = new BLL.PrvUser();
        /// <summary>
        /// 员工逻辑类
        /// </summary>
        private BLL.HREmpl hrEmplBLL = new BLL.HREmpl();
        //
        // GET: /Admin/WeekPlan/
        /// <summary>
        /// 工作周日志主页
        /// </summary>
        /// <returns>视图</returns>
        [AuthorityActionFilter("m_WeekPlan", Order = 1)]
        [LogPageActionFilter("工作周日志", Order = 2)]
        public ActionResult Index()
        {
            return View("Index");
        }

        /// <summary>
        /// 数据表页
        /// </summary>
        /// <returns>视图</returns>
        public ActionResult WeekPlanList(string mode = "")
        {
            int gowk = 0;
            BLL.WeekPlan weekPlanBll = new BLL.WeekPlan();
            DataSet dsdate = weekPlanBll.GetDate(gowk);
            ViewData["wk"] = dsdate.Tables[0].Rows[0]["wk"].ToString();
            ViewData["wk1"] = dsdate.Tables[0].Rows[0]["wk1"].ToString();

            DataSet dsweek = weekPlanBll.GetTime(DateTime.Parse(ViewData["wk1"].ToString()).ToString("yyyy-MM-dd"));
            ViewData["week"] = dsweek.Tables[0].Rows[0]["w"].ToString();
            DataSet dsyear = weekPlanBll.GetYear(DateTime.Parse(ViewData["wk1"].ToString()).ToString("yyyy-MM-dd"));
            ViewData["year"] = dsyear.Tables[0].Rows[0]["y"].ToString();

            ViewData["user_name"] = OperateSession.get("UserName");

            BLL.ICACDocument icacDoucumentBll = new BLL.ICACDocument();
            DataSet dsicacDoucument = icacDoucumentBll.GetPath();
            ViewData["dw"] = "#";
            ViewData["ns"] = "#";
            if (dsicacDoucument.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < dsicacDoucument.Tables[0].Rows.Count; i++)
                {
                    if (dsicacDoucument.Tables[0].Rows[i]["FTitle"].ToString().Trim() == "单位廉效风险防控登记表")
                    {
                        ViewData["dw"] = "~" + dsicacDoucument.Tables[0].Rows[i]["FAttachSvrFileName"].ToString();
                    }
                    else
                    {
                        ViewData["ns"] = "~" + dsicacDoucument.Tables[0].Rows[i]["FAttachSvrFileName"].ToString();
                    }
                }
            }


            BLL.ICACDeptDoc icacDeptDocBll = new BLL.ICACDeptDoc();
            DataSet dsicacDeptDoc = icacDeptDocBll.GetPath();
            StringBuilder strPath = new StringBuilder();
            if (dsicacDeptDoc.Tables[0].Rows.Count > 0)
            {
                for (int j = 0; j < dsicacDeptDoc.Tables[0].Rows.Count; j++)
                {
                    strPath.Append("<td height='50' align='center' width='40'><a href='" + dsicacDeptDoc.Tables[0].Rows[j]["FAttachSvrFileName"].ToString() + "'>");
                    strPath.Append(dsicacDeptDoc.Tables[0].Rows[j]["FAttachOldFileName"].ToString());
                    strPath.Append("<br /></a></td>");
                    if ((j + 1) % 8 == 0)
                    {
                        strPath.Append("</tr>");
                        strPath.Append("<tr>");
                    }
                }
                if (dsicacDeptDoc.Tables[0].Rows.Count % 8 != 0)
                {
                    int hr = dsicacDeptDoc.Tables[0].Rows.Count % 8;
                    hr = 8 - hr;
                    for (int k = 0; k < hr; k++)
                    {
                        strPath.Append("<td width='40'>");
                        strPath.Append("&nbsp;</td>");
                    }
                }

            }
            ViewData["strPath"] = strPath;



            Model.WeekPlan weekPlanModel = new Model.WeekPlan();          

            DataSet dsnextWeek = weekPlanBll.GetTime(DateTime.Parse(ViewData["wk1"].ToString()).AddDays(7).ToString("yyyy-MM-dd"));
            ViewData["nextWeek"] = dsnextWeek.Tables[0].Rows[0]["w"].ToString();
            DataSet dsnextyear = weekPlanBll.GetYear(DateTime.Parse(ViewData["wk1"].ToString()).AddDays(7).ToString("yyyy-MM-dd"));
            ViewData["nextYear"] = dsnextyear.Tables[0].Rows[0]["y"].ToString();
            string week = ViewData["nextWeek"].ToString();
            string year = ViewData["nextYear"].ToString();

            ViewData["tishi"] = "";
            if (!weekPlanBll.Exists(decimal.Parse(week), decimal.Parse(year), OperateSession.get("FEmplNo"), GlobalConstant.ENTITYNO))
            {
                ViewData["tishi"] = "<font color='red'>计划未录入</font>";
            }
            else
            {
                weekPlanModel = weekPlanBll.GetModel(decimal.Parse(week), decimal.Parse(year), OperateSession.get("FEmplNo"), GlobalConstant.ENTITYNO);
                if (weekPlanModel.FStatus == "N")
                {
                    ViewData["tishi"] = "<font color='red'>计划领导审核未通过</font>";
                }
                else if (weekPlanModel.FStatus == "Y")
                {
                    ViewData["tishi"] = "<font color='red'>计划已审核</font>";
                }
                else
                {

                    ViewData["tishi"] = "<font color='red'>计划领导未审核</font>";
                }
            }

            int lr = 0;
            int flag = -1;
            BLL.Daily dailyBll = new BLL.Daily();
            BLL.WorkCalendar workCalendarBll = new BLL.WorkCalendar();
            DataSet dsday;
            DataSet dshol;
            for (int i = 0; i < 14; i++)
            {
                dsday = dailyBll.GetDay(i);
                DateTime dt = DateTime.Parse(dsday.Tables[0].Rows[0]["wk"].ToString());
                DateTime dt1 = DateTime.Parse("2011-05-29");
                if (dt <= dt1)
                {
                    lr++;
                    continue;
                }
                DataSet ds = workCalendarBll.GetWorkDay(dt.ToString("yyyy-MM-dd"));

                if (ds.Tables[0].Rows.Count > 0)
                {
                    //休息的不计算
                    string pd = dailyBll.Pd(dt);
                    if (pd == "1")
                    {
                        if (i <= 6 && !dailyBll.Exists(GlobalConstant.ENTITYNO, OperateSession.get("FEmplNo"), dt))
                        {
                            flag = -2;
                        }
                    }
                }
                if (dailyBll.Exists(GlobalConstant.ENTITYNO, OperateSession.get("FEmplNo"), dt))
                {
                    lr++;
                }
                else
                {
                    dshol = dailyBll.GetHol(dt);
                    if (dshol.Tables[0].Rows.Count > 0)
                    {
                        if (dshol.Tables[0].Rows[0]["cou"].ToString() == "1")
                        {
                            lr++;
                        }
                        else
                        {
                            if (i <= 6)
                            {
                                flag = -2;
                            }
                        }
                    }
                }

            }

            if (14 - lr == 0)
            {
                flag = 0;
            }
            ViewData["tianshu"] = "";
            if (14 - lr > 0)
            {
                ViewData["tianshu"] = "(还有<font color='red'>" + (14 - lr).ToString() + "</font>天未补录工作日志)";
            }

            ViewData["flag"] = flag;

            string deptNo = OperateSession.get(GlobalConstant.PARAM_DEPTNO);
            string entity = GlobalConstant.ENTITYNO;
            string emplNo = OperateSession.get(GlobalConstant.PARAM_FEMPLNO);
            BLL.HREmpl hrEmplBLL = new BLL.HREmpl();
            //获取用户的所在部门，包括多岗位
            DataSet dsEmplDept = hrEmplBLL.GetEmplFromViewByEmplNo(emplNo, entity);
            List<string> deptNoList = new List<string>();

            if (dsEmplDept.Tables[0].Rows.Count > 0)
            {
                DataTable dt = dsEmplDept.Tables[0];
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    deptNoList.Add(dt.Rows[i]["FDeptNo"].ToString());

                }

            }
            DataSet dsemp = weekPlanBll.GetEmpNoByDeptNoList(deptNoList);

            //DataSet dsemp = weekPlanBll.GetEmpNo(deptNo);
            DataSet dsnoauin = null;
            int cou = 0;
            if (dsemp.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < dsemp.Tables[0].Rows.Count; i++)
                {
                    dsnoauin = weekPlanBll.GetCou(dsemp.Tables[0].Rows[i]["FEmplNo"].ToString(), entity);
                    if (dsnoauin.Tables[0].Rows.Count > 0)
                    {
                        for (int j = 0; j < dsnoauin.Tables[0].Rows.Count; j++)
                        {
                            cou += int.Parse(dsnoauin.Tables[0].Rows[j]["cou"].ToString());
                        }
                    }
                }
            }
            else
            {
                dsnoauin = null;
            }

            ViewData["cou1"] = cou;


            StringBuilder strdept = new StringBuilder();
            DataSet dsdept = weekPlanBll.GetCheckDept();

            if (dsdept.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < dsdept.Tables[0].Rows.Count; i++)
                {

                    DataSet dsempcheck = weekPlanBll.GetChechEmp(dsdept.Tables[0].Rows[i]["FDeptNo"].ToString());
                    if (dsempcheck.Tables[0].Rows.Count > 0)
                    {
                        strdept.Append("<table width='233' cellpadding='0' cellspacing='0' class='lefttable'><tr><td height='30' class='lefttitle'><br />"
                            + dsdept.Tables[0].Rows[i]["FDeptName"].ToString() + "</td></tr>");
                        strdept.Append("<tr><td><div class='sub'><ul>");
                        for (int j = 0; j < dsempcheck.Tables[0].Rows.Count; j++)
                        {
                            strdept.Append("<a href='" + Url.Action("EmplLook", "WeekPlan", new { gowk = 0, empNo = dsempcheck.Tables[0].Rows[j]["FEmplNo"].ToString() }) + "' style= 'cursor:hand;'><li>");
                            strdept.Append(dsempcheck.Tables[0].Rows[j]["FEmpName"].ToString());
                            strdept.Append("</li></a>");
                        }

                        strdept.Append("</ul></div></td></tr>");
                        strdept.Append("</table>");
                    }
                }
            }

            ViewData["strdept"] = strdept.ToString();

            

            ///此人是不是正级(副级)
            ///
            BLL.HREmpl emplBll = new BLL.HREmpl();
            bool istrue = emplBll.IsMainOrSub(emplNo);
            ViewData["isture"] = "false";
            if (istrue)
            {
                ViewData["isture"] = "true";
            }


            ///判断两张表的权限
            ViewData["List1"] = "false";
            ViewData["List2"] = "false";

            DAL.PrvFunctList prvFuncListDal = new DAL.PrvFunctList();
            List<Model.PrvFunctList> prvFunctList = prvFuncListDal.GetPrvFunctList(emplNo);
            var query1 = prvFunctList.Where(s => s.FFunctNo == "m_AcDeptTimesList");
            if (query1.Count() > 0)
            {
                ViewData["List1"] = "true";
            }
            var query2 = prvFunctList.Where(s => s.FFunctNo == "m_NoWeekPlanList");
            if (query2.Count() > 0)
            {
                ViewData["List2"] = "true";
            }

            ViewData["mode"] = mode;

            return View(weekPlanModel);
        }


        /// <summary>
        /// 上传文件
        /// </summary>
        /// <returns>视图</returns>
        public ActionResult Upload()
        {
            BLL.WeekPlan weekPlanBll = new BLL.WeekPlan();
            DataSet ds = weekPlanBll.GetDept();
            string str = "";
            StringBuilder deptNo = new StringBuilder();
            if (ds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    if (ds.Tables[0].Rows[i]["FAttachOldFileName"].ToString() == "")
                    {
                        str += ds.Tables[0].Rows[i]["FDeptName"].ToString() + ",";
                        deptNo.Append(ds.Tables[0].Rows[i]["FDeptNo"].ToString() + ",");
                    }
                    else
                    {
                        str += ds.Tables[0].Rows[i]["FDeptName"].ToString() + ",";
                        deptNo.Append(ds.Tables[0].Rows[i]["FDeptNo"].ToString() + ",");
                    }

                }
            }
            string[] arr = str.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
            ViewData["arr"] = arr;
            ViewData["deptNo"] = deptNo;

            DataSet dsold = weekPlanBll.GetDept();
            string strold = "";
            if (ds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    if (ds.Tables[0].Rows[i]["FAttachOldFileName"].ToString() == "")
                    {
                        strold += "暂时没有上传文件" + ",";

                    }
                    else
                    {
                        strold += ds.Tables[0].Rows[i]["FAttachOldFileName"].ToString() + ",";

                    }

                }
            }

            string[] arrold = strold.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
            ViewData["arrold"] = arrold;

            ///-------

            Model.ICACDeptDoc icacDeptDocModel = new Model.ICACDeptDoc();

            BLL.ICACDocument icacDoucumentBll = new BLL.ICACDocument();
            Model.ICACDocument icacDoucumentModel = new Model.ICACDocument();
            DataSet dsicacDoucument = icacDoucumentBll.GetPath();
            ViewData["dw"] = "暂时没有上传文件";
            ViewData["ns"] = "暂时没有上传文件";
            StringBuilder dw = new StringBuilder();
            StringBuilder ns = new StringBuilder();
            if (dsicacDoucument.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < dsicacDoucument.Tables[0].Rows.Count; i++)
                {
                    if (dsicacDoucument.Tables[0].Rows[i]["FTitle"].ToString().Trim() == "单位廉效风险防控登记表")
                    {
                        ViewData["dw"] = dsicacDoucument.Tables[0].Rows[i]["FTitle"].ToString();
                        dw.Append(dsicacDoucument.Tables[0].Rows[i]["FTitle"].ToString());
                    }
                    else
                    {
                        ViewData["ns"] = dsicacDoucument.Tables[0].Rows[i]["FTitle"].ToString();
                        ns.Append(dsicacDoucument.Tables[0].Rows[i]["FTitle"].ToString());
                    }
                }
            }

            ViewData["dwtitle"] = dw;
            ViewData["nstitle"] = ns;

            ElingOA6_Admin_DSJCJ.Areas.Admin.Models.WeekPlanViewModel weekPlanViewModel =
              new Models.WeekPlanViewModel(icacDoucumentModel, icacDeptDocModel);

            return View("Upload", weekPlanViewModel);
        }
        /// <summary>
        /// 填写日志页面
        /// </summary>
        /// <param name="gowk">参数</param>
        /// <param name="week">周</param> 
        /// <returns>视图</returns>
        public ActionResult AddWeek(int gowk, string week, string mode = "")
        {
            ViewData["prev"] = gowk - 1;
            ViewData["next"] = gowk + 1;
            BLL.WeekPlan weekPlanBll = new BLL.WeekPlan();
            DataSet dsdate = weekPlanBll.GetDate(gowk);
            ViewData["wk"] = dsdate.Tables[0].Rows[0]["wk"].ToString();
            ViewData["wk1"] = dsdate.Tables[0].Rows[0]["wk1"].ToString();

            DataSet ds = weekPlanBll.GetTime(DateTime.Parse(ViewData["wk1"].ToString()).ToString("yyyy-MM-dd"));
            ViewData["week"] = int.Parse(ds.Tables[0].Rows[0]["w"].ToString());
            DataSet dsyear = weekPlanBll.GetYear(DateTime.Parse(ViewData["wk1"].ToString()).ToString("yyyy-MM-dd"));
            ViewData["year"] = dsyear.Tables[0].Rows[0]["y"].ToString();
            ViewData["user_name"] = OperateSession.get("UserName");

            ViewData["gowk"] = gowk;

            week = ViewData["week"].ToString();
            string year = ViewData["year"].ToString();
        
            DataSet dstimediff = weekPlanBll.GetTimeDiff(gowk);
            if (int.Parse(dstimediff.Tables[0].Rows[0]["d"].ToString()) < -28)
            {
                Response.Write("<script>alert('您只能提前四周录入工作计划！');window.location.href ='" + Url.Action("WeekPlanList", "WeekPlan", new { gowk = 0 }) + "';</script>");
                Response.Flush();
                Response.End();
            }

            Model.WeekPlan weekPlanModel = new Model.WeekPlan();

            if (!weekPlanBll.Exists(decimal.Parse(week), decimal.Parse(year), OperateSession.get("FEmplNo"), GlobalConstant.ENTITYNO))
            {

                weekPlanModel.FContent = "";
                ViewData["up"] = true;
                ViewData["type"] = "add";
                ViewData["lastUpdate"] = "";
                ViewData["last"] = "";
            }
            else
            {

                ViewData["up"] = false;
                weekPlanModel = weekPlanBll.GetModel(decimal.Parse(week), decimal.Parse(year), OperateSession.get("FEmplNo"), GlobalConstant.ENTITYNO);
                ViewData["type"] = "edit";
                ViewData["id"] = weekPlanModel.FWeekPlan;

                ViewData["lastUpdate"] = "最后更新时间: " + weekPlanModel.FUpdDate.ToString("yyyy-MM-dd");
                ViewData["last"] = "";
                if (weekPlanModel.FStatus == "")
                {
                    ViewData["lastUpdate"] += "未审";
                    ViewData["last"] = "";
                }
                else if (weekPlanModel.FStatus == "N")
                {
                    ViewData["last"] = "未通过请更新";

                }
                else
                {

                    ViewData["isvisible"] = "false";
                }

            }

            ViewData["mode"] = mode;

            return View(weekPlanModel);
        }

        /// <summary>
        /// 保存附件
        /// </summary>
        /// <param name="icacDoucumentModel">单位，内设机构的model对象</param>
        /// <param name="icacDeptDoc">个人的model的对象</param>
        /// <returns>视图</returns>
        public ActionResult SaveFile(Model.ICACDocument icacDoucumentModel, Model.ICACDeptDoc icacDeptDocModel)
        {
            int gowk = 0;
            BLL.WeekPlan weekPlanBll = new BLL.WeekPlan();
            DataSet dsdate = weekPlanBll.GetDate(gowk);
            ViewData["wk"] = dsdate.Tables[0].Rows[0]["wk"].ToString();
            ViewData["wk1"] = dsdate.Tables[0].Rows[0]["wk1"].ToString();

            DataSet dsweek = weekPlanBll.GetTime(DateTime.Parse(ViewData["wk1"].ToString()).ToString("yyyy-MM-dd"));
            ViewData["week"] = dsweek.Tables[0].Rows[0]["w"].ToString();
           
            ViewData["user_name"] = OperateSession.get("UserName");

            BLL.ICACDocument icacDoucumentBll = new BLL.ICACDocument();
            DataSet dsicacDoucument = icacDoucumentBll.GetPath();
            ViewData["dw"] = "#";
            ViewData["ns"] = "#";
            if (dsicacDoucument.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < dsicacDoucument.Tables[0].Rows.Count; i++)
                {
                    if (dsicacDoucument.Tables[0].Rows[i]["FAttachDesc"].ToString() == "单位廉效风险防控登记表")
                    {
                        ViewData["dw"] = "~" + dsicacDoucument.Tables[0].Rows[i]["FAttachSvrFileName"].ToString();
                    }
                    else
                    {
                        ViewData["ns"] = "~" + dsicacDoucument.Tables[0].Rows[i]["FAttachSvrFileName"].ToString();
                    }
                }
            }


            BLL.ICACDeptDoc icacDeptDocBll = new BLL.ICACDeptDoc();
            DataSet dsicacDeptDoc = icacDeptDocBll.GetPath();
            string strPath = "";
            if (dsicacDeptDoc.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < dsicacDeptDoc.Tables[0].Rows.Count; i++)
                {
                    strPath += "~" + dsicacDeptDoc.Tables[0].Rows[i]["FAttachSvrFileName"].ToString() + ",";
                }
            }
            string[] arrPath = strPath.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);

            DataSet ds = weekPlanBll.GetDept();
            string str = "";
            if (ds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    str += ds.Tables[0].Rows[i]["FDeptName"].ToString() + ",";
                }
            }
            string[] arr = str.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
            ViewData["arr"] = arr;

            ActionResult actionResult = null;
            try
            {
                string dwtitle = Fetch.Post("hiddwtitle");

                ///附件上传
                UploadedFile[] uploadFiles = UploadControlExtension.GetUploadedFiles("uploaddw");
                if (uploadFiles.Length > 0 && null != uploadFiles)
                {
                    for (int i = 0; i < uploadFiles.Length; i++)
                    {
                        UploadedFile upload = uploadFiles[i];
                        if (upload.FileName != "")
                        {
                            if (upload != null)
                            {
                                string backname = upload.FileName.Substring(upload.FileName.LastIndexOf('.') + 1);

                                string entityNo = GlobalConstant.ENTITYNO;

                                string dest_dir = "Publish/jxtz/" + entityNo + "/upload/";

                                string svrFileName = Path.GetFileNameWithoutExtension(upload.FileName);//上传的文件名

                                string uploadoffiepath = Server.MapPath(Url.Content("~") + dest_dir);//上传文件的路径

                                if (!Directory.Exists(uploadoffiepath))//如果不存在就创建
                                {
                                    Directory.CreateDirectory(uploadoffiepath);
                                }

                                if (!icacDoucumentBll.Exists(dwtitle))
                                {
                                    icacDoucumentModel.FICACDocumentID = icacDoucumentModel.FICACDocumentID;
                                    icacDoucumentModel.FTitle = svrFileName;
                                    icacDoucumentModel.FAttachOldFileName = Path.GetFileNameWithoutExtension(upload.FileName) + Path.GetExtension(upload.FileName).ToLower();
                                    icacDoucumentModel.FAttachSvrFileName = Url.Content("~") + dest_dir + Path.GetFileNameWithoutExtension(upload.FileName) + Path.GetExtension(upload.FileName).ToLower();
                                    icacDoucumentModel.FAttachFileExt = backname;
                                    icacDoucumentModel.FAttachDesc = Fetch.Post("dwFAttachDesc");
                                    icacDoucumentModel.FInsDate = DateTime.Now;

                                    icacDoucumentBll = new BLL.ICACDocument();
                                    icacDoucumentBll.Add(icacDoucumentModel);
                                }
                                else
                                {
                                    icacDoucumentModel = icacDoucumentBll.GetModel(dwtitle);

                                    icacDoucumentModel.FICACDocumentID = icacDoucumentModel.FICACDocumentID;
                                    icacDoucumentModel.FTitle = svrFileName;
                                    icacDoucumentModel.FAttachOldFileName = Path.GetFileNameWithoutExtension(upload.FileName) + Path.GetExtension(upload.FileName).ToLower();
                                    icacDoucumentModel.FAttachSvrFileName = Url.Content("~") + dest_dir + Path.GetFileNameWithoutExtension(upload.FileName) + Path.GetExtension(upload.FileName).ToLower();
                                    icacDoucumentModel.FAttachFileExt = backname;
                                    icacDoucumentModel.FAttachDesc = Fetch.Post("dwFAttachDesc");
                                    icacDoucumentModel.FInsDate = DateTime.Now;
                                    ///
                                    List<string> imgPathList = GetPathListdw(dwtitle, icacDoucumentModel.FICACDocumentID);
                                    DeleteDoc(imgPathList);
                                    icacDoucumentBll.Update(icacDoucumentModel);
                                }

                                upload.SaveAs(uploadoffiepath + svrFileName + "." + backname);
                            }
                        }
                    }
                    actionResult = View("Upload", icacDoucumentModel);
                }

                string nstitle = Fetch.Post("hidnstitle");
                UploadedFile[] uploadFiles1 = UploadControlExtension.GetUploadedFiles("uploadnsjg");
                if (uploadFiles1.Length > 0 && null != uploadFiles1)
                {
                    for (int i = 0; i < uploadFiles1.Length; i++)
                    {
                        UploadedFile upload = uploadFiles1[i];
                        if (upload.FileName != "")
                        {
                            if (upload != null)
                            {
                                string backname = upload.FileName.Substring(upload.FileName.LastIndexOf('.') + 1);

                                string entityNo = GlobalConstant.ENTITYNO;

                                string dest_dir = "Publish/jxtz/" + entityNo + "/upload/";

                                string svrFileName = Path.GetFileNameWithoutExtension(upload.FileName);//上传的文件名

                                string uploadoffiepath = Server.MapPath(Url.Content("~") + dest_dir);//上传文件的路径

                                if (!Directory.Exists(uploadoffiepath))//如果不存在就创建
                                {
                                    Directory.CreateDirectory(uploadoffiepath);
                                }



                                if (!icacDoucumentBll.Exists(nstitle))
                                {

                                    icacDoucumentModel.FICACDocumentID = icacDoucumentModel.FICACDocumentID;
                                    icacDoucumentModel.FTitle = svrFileName;
                                    icacDoucumentModel.FAttachOldFileName = Path.GetFileNameWithoutExtension(upload.FileName) + Path.GetExtension(upload.FileName).ToLower();
                                    icacDoucumentModel.FAttachSvrFileName = Url.Content("~") + dest_dir + Path.GetFileNameWithoutExtension(upload.FileName) + Path.GetExtension(upload.FileName).ToLower();
                                    icacDoucumentModel.FAttachFileExt = backname;
                                    icacDoucumentModel.FAttachDesc = Fetch.Post("nsFAttachDesc");
                                    icacDoucumentModel.FInsDate = DateTime.Now;

                                    icacDoucumentBll = new BLL.ICACDocument();
                                    icacDoucumentBll.Add(icacDoucumentModel);
                                }
                                else
                                {

                                    icacDoucumentModel = icacDoucumentBll.GetModel(nstitle);
                                    icacDoucumentModel.FICACDocumentID = icacDoucumentModel.FICACDocumentID;
                                    icacDoucumentModel.FTitle = svrFileName;
                                    icacDoucumentModel.FAttachOldFileName = Path.GetFileNameWithoutExtension(upload.FileName) + Path.GetExtension(upload.FileName).ToLower();
                                    icacDoucumentModel.FAttachSvrFileName = Url.Content("~") + dest_dir + Path.GetFileNameWithoutExtension(upload.FileName) + Path.GetExtension(upload.FileName).ToLower();
                                    icacDoucumentModel.FAttachFileExt = backname;
                                    icacDoucumentModel.FAttachDesc = Fetch.Post("nsFAttachDesc");
                                    icacDoucumentModel.FInsDate = DateTime.Now;

                                    ///
                                    List<string> imgPathList = GetPathListdw(nstitle, icacDoucumentModel.FICACDocumentID);
                                    DeleteDoc(imgPathList);

                                    icacDoucumentBll.Update(icacDoucumentModel);
                                }
                                upload.SaveAs(uploadoffiepath + svrFileName + "." + backname);
                            }
                        }
                    }
                    actionResult = View("Upload", icacDoucumentModel);
                }

                ///个人的原文件显示

                string deptNo = Fetch.Post("hiddeptNo");
                ViewData["deptNo"] = deptNo;

                string[] arrdeptNo = deptNo.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);

                ///个人
                for (int i = 0; i < arr.Length; i++)
                {
                    UploadedFile[] uploadFiles2 = UploadControlExtension.GetUploadedFiles("upload" + i);
                    if (uploadFiles2.Length > 0 && null != uploadFiles2)
                    {
                        for (int j = 0; j < uploadFiles2.Length; j++)
                        {
                            UploadedFile upload = uploadFiles2[j];
                            if (upload.FileName != "")
                            {
                                if (upload != null)
                                {
                                    string backname = upload.FileName.Substring(upload.FileName.LastIndexOf('.') + 1);

                                    string entityNo = GlobalConstant.ENTITYNO;

                                    string dest_dir = "Publish/jxtz/" + entityNo + "/upload/";

                                    string svrFileName = Path.GetFileNameWithoutExtension(upload.FileName);//上传的文件名

                                    string uploadoffiepath = Server.MapPath(Url.Content("~") + dest_dir);//上传文件的路径

                                    if (!Directory.Exists(uploadoffiepath))//如果不存在就创建
                                    {
                                        Directory.CreateDirectory(uploadoffiepath);
                                    }
                                    if (!icacDeptDocBll.Exists(entityNo, arrdeptNo[i]))
                                    {
                                        ///增加
                                        icacDeptDocModel.FICACDeptDocID = icacDeptDocModel.FICACDeptDocID;
                                        icacDeptDocModel.FEntityNo = GlobalConstant.ENTITYNO;
                                        icacDeptDocModel.FDeptNo = arrdeptNo[i];
                                        icacDeptDocModel.FAttachOldFileName = Path.GetFileNameWithoutExtension(upload.FileName) + Path.GetExtension(upload.FileName).ToLower();
                                        icacDeptDocModel.FAttachSvrFileName = Url.Content("~") + dest_dir + Path.GetFileNameWithoutExtension(upload.FileName) + Path.GetExtension(upload.FileName).ToLower();
                                        icacDeptDocModel.FAttachFileExt = backname;
                                        icacDeptDocModel.FAttachDesc = Fetch.Post("upload" + i);
                                        icacDeptDocModel.FInsDate = DateTime.Now;

                                        icacDeptDocBll = new BLL.ICACDeptDoc();
                                        icacDeptDocBll.Add(icacDeptDocModel);
                                    }
                                    else
                                    {

                                        List<string> imgPathList = GetPathList(arrdeptNo[i], entityNo);
                                        DeleteDoc(imgPathList);
                                        ///更新
                                        icacDeptDocModel = icacDeptDocBll.GetModel(entityNo, arrdeptNo[i]);
                                        icacDeptDocModel.FICACDeptDocID = icacDeptDocModel.FICACDeptDocID;
                                        icacDeptDocModel.FEntityNo = GlobalConstant.ENTITYNO;
                                        icacDeptDocModel.FDeptNo = arrdeptNo[i];
                                        icacDeptDocModel.FAttachOldFileName = Path.GetFileNameWithoutExtension(upload.FileName) + Path.GetExtension(upload.FileName).ToLower();
                                        icacDeptDocModel.FAttachSvrFileName = Url.Content("~") + dest_dir + Path.GetFileNameWithoutExtension(upload.FileName) + Path.GetExtension(upload.FileName).ToLower();
                                        icacDeptDocModel.FAttachFileExt = backname;
                                        icacDeptDocModel.FAttachDesc = Fetch.Post("upload" + i);
                                        icacDeptDocModel.FInsDate = DateTime.Now;

                                        icacDeptDocBll.Update(icacDeptDocModel);

                                    }

                                    upload.SaveAs(uploadoffiepath + svrFileName + "." + backname);
                                }
                            }

                        }
                    }
                    actionResult = View("Upload", icacDeptDocModel);
                }
                ViewData["message"] = "操作成功";
                ViewData["IsClose"] = "Y";

            }
            catch (Exception)
            {
                ViewData["message"] = "操作失败";
                ViewData["IsClose"] = "N";

            }

            DataSet dsold = weekPlanBll.GetDept();
            string strold = "";
            if (ds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    if (ds.Tables[0].Rows[i]["FAttachOldFileName"].ToString() == "")
                    {
                        strold += "暂时没有上传文件" + ",";

                    }
                    else
                    {
                        strold += ds.Tables[0].Rows[i]["FAttachOldFileName"].ToString() + ",";

                    }

                }
            }

            string[] arrold = strold.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
            ViewData["arrold"] = arrold;



            return actionResult;
        }

        /// <summary>
        /// 删除保存在文件的图片
        /// </summary>
        /// <param name="strList">文件路径list</param>
        public void DeleteDoc(List<string> strList)
        {
            foreach (string strPath in strList)
            {
                GenerateUtil.DeleteFile(Url.Content("~") + strPath);
            }
        }
        /// <summary>
        /// 获取保存在硬盘中的文件路径
        /// </summary>
        /// <param name="title">主题</param>
        /// <param name="icacDocumentID">编号</param>
        /// <returns>list集合</returns>
        public List<string> GetPathListdw(string title, decimal icacDocumentID)
        {
            BLL.ICACDocument icacDoucumentBll = new BLL.ICACDocument();
            List<string> strList = icacDoucumentBll.GetSrvName(title, icacDocumentID);
            return strList;
        }

        /// <summary>
        /// 获取保存在硬盘中的文件路径
        /// </summary>
        /// <param name="dept">部门编号</param>
        /// <param name="strEntityNo">公司编号</param>
        /// <returns>图片路径</returns>

        public List<string> GetPathList(string dept, string entityNo)
        {
            BLL.ICACDeptDoc icacDeptDocBll = new BLL.ICACDeptDoc();
            List<string> strList = icacDeptDocBll.GetSrvName(dept, entityNo);
            return strList;
        }
        /// <summary>
        /// 保存修改日志
        /// </summary>
        /// <param name="weekPlanModel">weekplanmodel对象</param>
        /// <returns>视图</returns>
        [ValidateInput(false)]
        public ActionResult SaveWeekPlan(Model.WeekPlan weekPlanModel)
        {
            ViewData["user_name"] = Fetch.Post("hiduser_name");
            ViewData["prev"] = Fetch.Post("hidprev");
            ViewData["next"] = Fetch.Post("hidnext");
            ViewData["week"] = Fetch.Post("hidweek");
            ViewData["wk"] = Fetch.Post("hidwk");
            ViewData["wk1"] = Fetch.Post("hidwk1");
            ViewData["lastUpdate"] = Fetch.Post("hidlastUpdate");
            ViewData["last"] = Fetch.Post("hidlast");
            ViewData["up"] = false;
            ViewData["gowk"] = Fetch.Post("hidgowk");
            ViewData["year"] = Fetch.Post("hidyear");

            BLL.WeekPlan weekPlanBll = new BLL.WeekPlan();
            string type = Fetch.Post("hidtype");
            try
            {
                bool upcheck = CheckBoxExtension.GetValue<bool>("up");
               
                if (type == "add")
                {
                    if (upcheck)
                    {
                        weekPlanModel.FWeekPlan = weekPlanModel.FWeekPlan;
                        weekPlanModel.FEmplNo = OperateSession.get("FEmplNo");
                        weekPlanModel.FEntityNo = GlobalConstant.ENTITYNO;
                        weekPlanModel.FYear = decimal.Parse(Fetch.Post("hidyear"));
                        weekPlanModel.FWeek = decimal.Parse(Fetch.Post("hidweek"));
                        weekPlanModel.FBeginDate = DateTime.Parse(Fetch.Post("hidwk"));
                        weekPlanModel.FEndDate = DateTime.Parse(Fetch.Post("hidwk1"));

                        string html = Fetch.Post("FContent");

                        weekPlanModel.FContent = checkStr(NoHTML(html));
                        weekPlanModel.FInsDate = DateTime.Now;
                        weekPlanModel.FUpdDate = DateTime.Now;
                        weekPlanModel.FInsIP = GenerateUtil.GetClientIPv4Address();
                        weekPlanModel.FStatus = "";

                        if (weekPlanModel.FContent != "")
                        {

                            weekPlanBll.Add(weekPlanModel);
                        }
                    }


                }
                else if (type == "edit")
                {
                    if (upcheck)
                    {
                        weekPlanModel.FWeekPlan = decimal.Parse(Fetch.Post("hidid"));
                        weekPlanModel.FUpdDate = DateTime.Now;
                        string html = Fetch.Post("FContent");

                        weekPlanModel.FContent = checkStr(NoHTML(html));
                        weekPlanModel.FStatus = "";
                        if (weekPlanModel.FContent != "")
                        {
                            weekPlanBll.Update(weekPlanModel);
                        }
                    }
                }
                ViewData["message"] = "操作成功";
                ViewData["IsClose"] = "Y";

            }
            catch (Exception)
            {

                ViewData["message"] = "操作失败";
                ViewData["IsClose"] = "N";
            }

            ViewData["type"] = type;
            ViewData["id"] = Fetch.Post("hidid");

            return View("AddWeek", weekPlanModel);
        }

        /// <summary>
        /// 替换Html
        /// </summary>
        /// <param name="html"></param>
        /// <returns></returns>
        public string checkStr(string html)
        {
            System.Text.RegularExpressions.Regex regex1 = new System.Text.RegularExpressions.Regex(@"<script[\s\S]+</script *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regex2 = new System.Text.RegularExpressions.Regex(@" href *= *[\s\S]*script *:", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regex3 = new System.Text.RegularExpressions.Regex(@" no[\s\S]*=", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regex4 = new System.Text.RegularExpressions.Regex(@"<iframe[\s\S]+</iframe *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regex5 = new System.Text.RegularExpressions.Regex(@"<frameset[\s\S]+</frameset *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regex6 = new System.Text.RegularExpressions.Regex(@"\<img[^\>]+\>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regex7 = new System.Text.RegularExpressions.Regex(@"</p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regex8 = new System.Text.RegularExpressions.Regex(@"<p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regex9 = new System.Text.RegularExpressions.Regex(@"<[^>]*>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            //System.Text.RegularExpressions.Regex regex10 = new System.Text.RegularExpressions.Regex(@"<textarea[^>]+>).*?(<\/textarea>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            html = regex1.Replace(html, ""); //过滤<script></script>标记 
            html = regex2.Replace(html, ""); //过滤href=javascript: (<A>) 属性 
            html = regex3.Replace(html, " _disibledevent="); //过滤其它控件的on...事件 
            html = regex4.Replace(html, ""); //过滤iframe 
            html = regex5.Replace(html, ""); //过滤frameset 
            html = regex6.Replace(html, ""); //过滤frameset 
            html = regex7.Replace(html, ""); //过滤frameset 
            html = regex8.Replace(html, ""); //过滤frameset 
            html = regex9.Replace(html, "");
            //html = regex10.Replace(html, "");
            html = html.Replace(" ", "");
            html = html.Replace("</strong>", "");
            html = html.Replace("<strong>", "");
            //html = html.Replace("###!!", "<br />");
            return html;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="Htmlstring"></param>
        /// <returns></returns>
        private string NoHTML(string Htmlstring)
        {
            //删除脚本
            Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
            //删除HTML
            //Htmlstring = Regex.Replace(Htmlstring, @"<br />", "###!!", RegexOptions.IgnoreCase);
            //Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s]+", "\r\n", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"-->", "", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"<!--.*", "", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(quot|#34);", "\"", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(amp|#38);", "&", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(lt|#60);", "<", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(gt|#62);", ">", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(nbsp|#160);", "   ", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(iexcl|#161);", "\xa1", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(cent|#162);", "\xa2", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(pound|#163);", "\xa3", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(copy|#169);", "\xa9", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&#(\d+);", "", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"\<textarea[^\>]+\<textarea\>", "", RegexOptions.IgnoreCase);
            Htmlstring.Replace("<", "");
            Htmlstring.Replace(">", "");
            Htmlstring.Replace("\r\n", "\r\n");
           
            return Htmlstring;
        }

        /// <summary>
        /// table中的WIDTH和Class的属性去掉
        /// </summary>
        /// <param name="html"></param>
        /// <returns></returns>
        private string LimitWidth(string html) 
        {

            return html;
        }



        /// <summary>
        /// 审核页面
        /// </summary>      
        /// <param name="gowk">参数</param>
        /// <returns>视图</returns>
        public ActionResult CheckWeekPlan(int gowk = 0, string mode = "")
        {

            ViewData["prev"] = gowk - 1;
            ViewData["next"] = gowk + 1;
            BLL.WeekPlan weekPlanBll = new BLL.WeekPlan();
            DataSet dsdate = weekPlanBll.GetDate(gowk);
            ViewData["wk"] = dsdate.Tables[0].Rows[0]["wk"].ToString();
            ViewData["wk1"] = dsdate.Tables[0].Rows[0]["wk1"].ToString();
            DataSet ds = weekPlanBll.GetTime(DateTime.Parse(ViewData["wk1"].ToString()).ToString("yyyy-MM-dd"));
            ViewData["week"] = int.Parse(ds.Tables[0].Rows[0]["w"].ToString());
            DataSet dsyear = weekPlanBll.GetYear(DateTime.Parse(ViewData["wk1"].ToString()).ToString("yyyy-MM-dd"));
            ViewData["year"] = dsyear.Tables[0].Rows[0]["y"].ToString();

            string deptNo = OperateSession.get("DeptNo");
            string entity = GlobalConstant.ENTITYNO;
            BLL.HRDept deptBll = new BLL.HRDept();

            string entityNo = GlobalConstant.ENTITYNO;
            string emplNo = OperateSession.get(GlobalConstant.PARAM_FEMPLNO);
            //获取用户的所在部门，包括多岗位
            DataSet dsEmplDept = hrEmplBLL.GetEmplFromViewByEmplNo(emplNo, entityNo);
            string deptName = "";
            List<string> deptNoList = new List<string>();
          
            if (dsEmplDept.Tables[0].Rows.Count > 0)
            {
                DataTable dt = dsEmplDept.Tables[0];
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    deptName += "'" + dt.Rows[i]["FDeptName"].ToString() + "',";
                    deptNoList.Add(dt.Rows[i]["FDeptNo"].ToString());

                }
                deptName = deptName.Substring(0, deptName.LastIndexOf(','));
                
            }
            ViewData["deptName"] = deptName;

            DataSet dsemp = weekPlanBll.GetEmpNoByDeptNoList(deptNoList);

            DataSet dsnoauin = null;

            DataTable dtWeekPlan = null;
            if (dsemp.Tables[0].Rows.Count > 0)
            {

                for (int i = 0; i < dsemp.Tables[0].Rows.Count; i++)
                {
                    dsnoauin = weekPlanBll.GetNoAuIn(dsemp.Tables[0].Rows[i]["FEmplNo"].ToString(), entity);

                    if (dsnoauin.Tables[0].Rows.Count > 0)
                    {
                        if (dtWeekPlan == null)
                        {
                            dtWeekPlan = dsnoauin.Tables[0].Clone();
                        }
                        for (int j = 0; j < dsnoauin.Tables[0].Rows.Count; j++)
                        {
                            dsnoauin.Tables[0].Rows[j]["FContent"] = "<B color='black'>" + DateTime.Parse(dsnoauin.Tables[0].Rows[j]["FBeginDate"].ToString()).ToString("yyyy.MM.dd")
                                      + " - " + DateTime.Parse(dsnoauin.Tables[0].Rows[j]["FEndDate"].ToString()).ToString("yyyy.MM.dd") + " "
                                      + dsemp.Tables[0].Rows[i]["FEmpName"].ToString() + ":</B><br />"
                                      + dsnoauin.Tables[0].Rows[j]["FContent"].ToString();

                            ViewData["id"] += dsnoauin.Tables[0].Rows[j]["FWeekPlan"].ToString() + ",";
                            object[] obj = new object[dsnoauin.Tables[0].Columns.Count];

                            dsnoauin.Tables[0].Rows[j].ItemArray.CopyTo(obj, 0);

                            dtWeekPlan.Rows.Add(obj);
                        }
                    }

                }


            }

            if (dtWeekPlan == null)
            {
                dtWeekPlan = new DataTable();
            }

            if (dtWeekPlan.Rows.Count > 0)
            {
                string[] strarr = new string[dtWeekPlan.Rows.Count];

                for (int i = 0; i < dtWeekPlan.Rows.Count; i++)
                {
                    strarr[i] = dtWeekPlan.Rows[i]["FContent"].ToString();
                }
                ViewData["strarr"] = strarr;
                ViewData["cou"] = strarr.Length;
                ViewData["lenght"] = strarr.Length;
            }
            else
            {
                string[] strarr = { };
                ViewData["strarr"] = strarr;
                ViewData["cou"] = "0";
                ViewData["lenght"] = strarr.Length;
            }

            ViewData["mode"] = mode;

            return View();
        }


        /// <summary>
        /// 审核保存
        /// </summary>
        /// <param name="weekPlanModel">weekPlanModel对象</param>
        /// <returns>视图</returns>
        [HttpPost]
        [ValidateInput(false)]
        public ActionResult SaveCheckWeekPlan(Model.WeekPlan weekPlanModel)
        {
            ActionResult actionResult = null;
            //审核的时候
            ViewData["cou"] = Fetch.Post("hidcou");
            string[] id = Fetch.Post("hidid").ToString().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
            BLL.WeekPlan weekPlanBLL = new BLL.WeekPlan();

            try
            {
                for (int i = 0; i < int.Parse(ViewData["cou"].ToString()); i++)
                {
                    weekPlanModel.FWeekPlan = decimal.Parse(id[i]);
                    weekPlanModel.FStatus = RadioButtonListExtension.GetValue<string>("a2" + i);
                    if (!string.IsNullOrEmpty(weekPlanModel.FStatus))
                    {
                        //已审核
                        weekPlanModel.FCheckEmpNo = OperateSession.get("FEmplNo");
                        weekPlanModel.FCheckDate = DateTime.Now;
                        weekPlanModel.FCheckIP = GenerateUtil.GetClientIPv4Address();
                        weekPlanBLL.UpdateCheck(weekPlanModel);
                    }
                }
                ViewData["RedirectURL"] = Url.Action("Index", "WeekPlan");
                actionResult = View("SuccessMessagePage");
            }
            catch (Exception)
            {
                Response.Write("<script>window.alert('操作失败');window.location.href='" + Url.Action("Index", "WeekPlan") + "';</script>");
                Response.Flush();
                Response.End();

            }
            return actionResult;
        }

        /// <summary>
        /// 工作计划未上报人员清单
        /// </summary>       
        /// <param name="gowk">参数</param>
        /// <returns>视图</returns>
        public ActionResult NoWeekPlanList(int gowk = 0, string mode = "font")
        {
            ViewData["prev"] = gowk - 1;
            ViewData["next"] = gowk + 1;
            BLL.WeekPlan weekPlanBll = new BLL.WeekPlan();
            DataSet dsdate = weekPlanBll.GetDate(gowk);
            ViewData["wk"] = dsdate.Tables[0].Rows[0]["wk"].ToString();
            ViewData["wk1"] = dsdate.Tables[0].Rows[0]["wk1"].ToString();

            DataSet ds = weekPlanBll.GetTime(DateTime.Parse(ViewData["wk1"].ToString()).ToString("yyyy-MM-dd"));
            ViewData["week"] = int.Parse(ds.Tables[0].Rows[0]["w"].ToString());
            DataSet dsyear = weekPlanBll.GetYear(DateTime.Parse(ViewData["wk1"].ToString()).ToString("yyyy-MM-dd"));
            ViewData["year"] = dsyear.Tables[0].Rows[0]["y"].ToString();
            DateTime beginDate = DateTime.Parse(ViewData["wk"].ToString());
            DateTime endDate = DateTime.Parse(ViewData["wk1"].ToString());


            ///未按时上报和未上报的 
            string loginId = OperateSession.get(GlobalConstant.PARAM_LOGINID);
            string entityNo = GlobalConstant.ENTITYNO;
            string emplNo = OperateSession.get(GlobalConstant.PARAM_FEMPLNO);

            StringBuilder htmlStrPlan = new StringBuilder();

            DataSet tmpNoPlan = weekPlanBll.GetNoWeekPlan(beginDate.ToString("yyyy-MM-dd"), endDate.ToString("yyyy-MM-dd"));
            DataSet dsnoplan = tmpNoPlan.Clone();
            dsnoplan.Tables.Add(new DataTable());
            string deptNos = "";//所属部门（多部门）
            string isLookAllDaily = "N";
            //获取当前登录人是否有查看全局的绩效台账的权限
            Model.PrvUser prvUserModel = prvUserBLL.GetModel(loginId, entityNo);
            if (prvUserModel != null)
            {
                isLookAllDaily = prvUserModel.FIsLookAllDaily;
                if (prvUserModel.FIsLookAllDaily == "N")
                {
                    //获取用户的所在部门，包括多岗位
                    DataSet dsEmplDept = hrEmplBLL.GetEmplFromViewByEmplNo(emplNo, entityNo);

                    if (dsEmplDept.Tables[0].Rows.Count > 0)
                    {
                        DataTable dt = dsEmplDept.Tables[0];
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            deptNos += "'" + dt.Rows[i]["FDeptNo"].ToString() + "',";

                        }
                        deptNos = deptNos.Substring(0, deptNos.LastIndexOf(','));

                    }
                }

            }
            if (deptNos != "")
            {
                DataRow[] drs = tmpNoPlan.Tables[0].Select("FDeptNo IN (" + deptNos + ")");

                foreach (DataRow dr in drs)
                {
                    dsnoplan.Tables[0].Rows.Add(dr.ItemArray);
                }
            }
            else
            {
                if (isLookAllDaily == "Y")
                {
                    dsnoplan = tmpNoPlan;
                }
            }
            if (DateTime.Now > beginDate)
            {
                //未按时上报，本周开始的第一天的前一天上报的周计划

                if (dsnoplan.Tables[0].Rows.Count > 0)
                {
                    string deptname = "";
                    int ss = 0;
                    int num = 0;
                    for (int i = 0; i < dsnoplan.Tables[0].Rows.Count; i++)
                    {
                        if (deptname != dsnoplan.Tables[0].Rows[i]["deptName"].ToString())
                        {
                            deptname = dsnoplan.Tables[0].Rows[i]["deptName"].ToString();
                            if (ss != 0) htmlStrPlan.Append("(共 " + num + " 人)<br />");
                            num = 1;
                            htmlStrPlan.Append("<B>" + deptname + "</B>" + ":");
                        }
                        else
                        {
                            num++;
                        }

                        htmlStrPlan.Append("&nbsp;<a href='" + Url.Action("EmplLook", "WeekPlan", new { gowk = gowk, empNo = dsnoplan.Tables[0].Rows[i]["FEmplNo"].ToString() }) + "'><span style='display:inline-block;cursor:hand;'>" + dsnoplan.Tables[0].Rows[i]["FEmpName"].ToString() + "</span></a>");
                        if (++ss % 10 == 0) htmlStrPlan.Append("");
                    }

                    if (deptname != "")
                    {
                        htmlStrPlan.Append("(共 " + num + " 人)");
                    }
                }
                else
                {
                    htmlStrPlan.Append("&nbsp;没有未按时上报的人员");
                }
            }
            else
            {
                htmlStrPlan.Append("&nbsp;没有未按时上报的人员");
            }


            ViewData["htmlStrPlan"] = htmlStrPlan;

            ///未按时审核
            ///

            StringBuilder htmlStrNoCheck = new StringBuilder();
            tmpNoPlan = weekPlanBll.GetNoCheck(beginDate.ToString("yyyy-MM-dd"), endDate.ToString("yyyy-MM-dd"));
            DataSet dsnocheck = tmpNoPlan.Clone();
            dsnocheck.Tables.Add(new DataTable());

            if (deptNos != "")
            {
                DataRow[] drs = tmpNoPlan.Tables[0].Select("FDeptNo IN (" + deptNos + ")");

                foreach (DataRow dr in drs)
                {
                    dsnocheck.Tables[0].Rows.Add(dr.ItemArray);
                }
            }
            else
            {
                if (isLookAllDaily == "Y")
                {
                    dsnocheck = tmpNoPlan;
                }
            }

            if (DateTime.Now > (beginDate.AddDays(1)))
            {
                //未按时审核，本周开始的第一天审核上周的周计划
                if (dsnocheck.Tables[0].Rows.Count > 0)
                {
                    string deptname = "";
                    int ss = 0;
                    int num = 0;
                    for (int i = 0; i < dsnocheck.Tables[0].Rows.Count; i++)
                    {
                        if (deptname != dsnocheck.Tables[0].Rows[i]["deptName"].ToString())
                        {
                            deptname = dsnocheck.Tables[0].Rows[i]["deptName"].ToString();
                            if (ss != 0) htmlStrNoCheck.Append("(共 " + num + " 人)<br />");
                            num = 1;
                            htmlStrNoCheck.Append("<B>" + deptname + "</B>" + ":");
                        }
                        else
                        {
                            num++;
                        }

                        if (dsnocheck.Tables[0].Rows[i]["TYPE"].ToString() == "1")
                        {
                            htmlStrNoCheck.Append("&nbsp;<a href='" + Url.Action("EmplLook", "WeekPlan", new { gowk = gowk, empNo = dsnocheck.Tables[0].Rows[i]["FEmplNo"].ToString() }) + "'><span style='display:inline-block;cursor:hand;color:orange'>" + dsnocheck.Tables[0].Rows[i]["FEmpName"].ToString() + "</span></a>");
                        }
                        else
                        {
                            htmlStrNoCheck.Append("&nbsp;<a href='" + Url.Action("EmplLook", "WeekPlan", new { gowk = gowk, empNo = dsnocheck.Tables[0].Rows[i]["FEmplNo"].ToString() }) + "'><span style='display:inline-block;cursor:hand;'>" + dsnocheck.Tables[0].Rows[i]["FEmpName"].ToString() + "</span></a>");
                        }
                        if (++ss % 8 == 0) htmlStrNoCheck.Append("");
                    }

                    if (deptname != "")
                    {
                        htmlStrNoCheck.Append("(共 " + num + " 人)<br />");
                    }

                }
                else
                {
                    htmlStrNoCheck.Append("&nbsp;没有未按时审核的人员");
                }
            }
            else
            {
                htmlStrNoCheck.Append("&nbsp;没有未按时审核的人员");
            }

            ViewData["htmlStrNoCheck"] = htmlStrNoCheck;

            ///日志未完整
            ///
            tmpNoPlan = weekPlanBll.GetNoReg(beginDate.ToString("yyyy-MM-dd"), endDate.ToString("yyyy-MM-dd"));
            DataSet dsnoreg = tmpNoPlan.Clone();
            dsnoreg.Tables.Add(new DataTable());

            if (deptNos != "")
            {
                DataRow[] drs = tmpNoPlan.Tables[0].Select("FDeptNo IN (" + deptNos + ")");

                foreach (DataRow dr in drs)
                {
                    dsnoreg.Tables[0].Rows.Add(dr.ItemArray);
                }
            }
            else
            {
                if (isLookAllDaily == "Y")
                {
                    dsnoreg = tmpNoPlan;
                }
            }
            StringBuilder htmlStrNoReg = new StringBuilder();
            if (DateTime.Now.Date > beginDate)
            {
                if (dsnoreg.Tables[0].Rows.Count > 0)
                {
                    Dictionary<string, string> deptList = new Dictionary<string, string>();
                    if (dsnoreg.Tables[0].Rows.Count > 0)
                    {
                        for (int i = 0; i < dsnoreg.Tables[0].Rows.Count; i++)
                        {
                            if (!deptList.Keys.Contains(dsnoreg.Tables[0].Rows[i]["FDeptNo"].ToString()))
                            {
                                deptList.Add(dsnoreg.Tables[0].Rows[i]["FDeptNo"].ToString(), dsnoreg.Tables[0].Rows[i]["deptName"].ToString());
                            }
                        }
                    }
                    //循环部门
                    foreach (KeyValuePair<string, string> dept in deptList)
                    {
                        DataRow[] dataRows = dsnoreg.Tables[0].Select("FDeptNo='" + dept.Key + "'");
                        int num = dataRows.Count();
                        htmlStrNoReg.Append("<B>" + dept.Value + "</B>" + ":");

                        foreach (DataRow dr in dataRows)
                        {
                            if (dr["TYPE"].ToString() == "1")
                            {
                                htmlStrNoReg.Append("&nbsp;<a href='" + Url.Action("EmplLook", "WeekPlan", new { gowk = gowk, empNo = dr["FEmplNo"].ToString() }) + "'><span style='display:inline-block;cursor:hand;'>" + dr["FEmpName"].ToString() + "</span></a>");
                            }
                            else
                            {
                                htmlStrNoReg.Append("&nbsp;<a href='" + Url.Action("EmplLook", "WeekPlan", new { gowk = gowk, empNo = dr["FEmplNo"].ToString() }) + "'><span style='display:inline-block;cursor:hand;'>" + dr["FEmpName"].ToString() + "</span></a>");
                            }
                        }
                        htmlStrNoReg.Append("(共 " + num + " 人)<br />");
                    }


                }
                else
                {
                    htmlStrNoReg.Append("&nbsp;没有日志未完整登记记录的人员");
                }
            }
            else
            {
                htmlStrNoReg.Append("&nbsp;没有日志未完整登记记录的人员");
            }
            ViewData["htmlStrNoReg"] = htmlStrNoReg;

            ViewData["mode"] = mode;

            return View();
        }


        /// <summary>
        /// 科室应扣实际次数 
        /// </summary>
        /// <returns>视图</returns>
        public ActionResult AcDeptTimesList(string mode = "font")
        {
            BLL.WeekPlan weekPlanBll = new BLL.WeekPlan();
            int gowk = 0;
            DataSet dsdate = weekPlanBll.GetDate(gowk);
            ViewData["wk"] = dsdate.Tables[0].Rows[0]["wk"].ToString();
            ViewData["wk1"] = dsdate.Tables[0].Rows[0]["wk1"].ToString();

            //DataSet dsyear = weekPlanBll.GetYear(DateTime.Parse(ViewData["wk1"].ToString()).ToString("yyyy-MM-dd"));
            //ViewData["year"] = dsyear.Tables[0].Rows[0]["y"].ToString();
            //decimal year = decimal.Parse(ViewData["year"].ToString());

            string entityNo = GlobalConstant.ENTITYNO;
            DataSet dsalldate = weekPlanBll.GetAllData(entityNo);
            StringBuilder actimes = new StringBuilder();
            if (dsalldate.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < dsalldate.Tables[0].Rows.Count; i++)
                {
                    if (dsalldate.Tables[0].Rows[i]["sumcount"].ToString() != "0")
                    {
                        actimes.Append("<tr>");
                        actimes.Append("<td align='center'>" + dsalldate.Tables[0].Rows[i]["FYear"].ToString() + "</td>");
                        actimes.Append("<td align='center'>" + DateTime.Parse(dsalldate.Tables[0].Rows[i]["FEndDate"].ToString()).Month + "</td>");
                        actimes.Append("<td align='center'>");
                        actimes.Append(DateTime.Parse(dsalldate.Tables[0].Rows[i]["FBeginDate"].ToString()).ToString("yyyy.MM.dd") + "-");
                        actimes.Append(DateTime.Parse(dsalldate.Tables[0].Rows[i]["FEndDate"].ToString()).ToString("yyyy.MM.dd") + "</td>");
                        actimes.Append("<td align='center'>" + dsalldate.Tables[0].Rows[i]["FWeek"].ToString() + "</td>");
                        actimes.Append("<td align='center'>" + dsalldate.Tables[0].Rows[i]["FDeptName"].ToString() + "</td>");
                        actimes.Append("<td align='center'>" + dsalldate.Tables[0].Rows[i]["counts"].ToString() + "</td>");
                        actimes.Append("<td align='center'>" + dsalldate.Tables[0].Rows[i]["count3"].ToString() + "</td>");
                        actimes.Append("<td align='center'>" + dsalldate.Tables[0].Rows[i]["sumcount"].ToString() + "</td>");

                        actimes.Append("</tr>");
                    }
                    else
                    {
                        actimes.Append("");
                    }
                }
            }
            ViewData["actimes"] = actimes;
            ViewData["mode"] = mode;//前后台区分
            return View();
        }

        /// <summary>
        /// 人员查看
        /// </summary>
        /// <param name="gowk">周参数</param>
        /// <param name="empNo">人员编号</param>
        /// <returns>查看视图</returns>
        public ActionResult EmplLook(int gowk, string empNo, string mode = "")
        {
            ViewData["gowk"] = gowk;
            ViewData["prev"] = gowk - 1;
            ViewData["next"] = gowk + 1;
            BLL.WeekPlan weekPlanBll = new BLL.WeekPlan();
            DataSet dsdate = weekPlanBll.GetDate(gowk);
            ViewData["wk"] = dsdate.Tables[0].Rows[0]["wk"].ToString();
            ViewData["wk1"] = dsdate.Tables[0].Rows[0]["wk1"].ToString();

            DataSet ds = weekPlanBll.GetTime(DateTime.Parse(ViewData["wk1"].ToString()).ToString("yyyy-MM-dd"));
            ViewData["week"] = int.Parse(ds.Tables[0].Rows[0]["w"].ToString());
            DataSet dsyear = weekPlanBll.GetYear(DateTime.Parse(ViewData["wk1"].ToString()).ToString("yyyy-MM-dd"));
            ViewData["year"] = dsyear.Tables[0].Rows[0]["y"].ToString();
            StringBuilder strdept = new StringBuilder();
            DataSet dsdept = weekPlanBll.GetCheckDept();

            if (dsdept.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < dsdept.Tables[0].Rows.Count; i++)
                {

                    DataSet dsempcheck = weekPlanBll.GetChechEmp(dsdept.Tables[0].Rows[i]["FDeptNo"].ToString());
                    if (dsempcheck.Tables[0].Rows.Count > 0)
                    {
                        strdept.Append("<table width='233' cellpadding='0' cellspacing='0' class='lefttable'><tr><td height='30' class='lefttitle'><br />"
                            + dsdept.Tables[0].Rows[i]["FDeptName"].ToString() + "</td></tr>");
                        strdept.Append("<tr><td><div class='sub'><ul>");
                        for (int j = 0; j < dsempcheck.Tables[0].Rows.Count; j++)
                        {
                            strdept.Append("<a href='" + Url.Action("EmplLook", "WeekPlan", new { gowk = 0, empNo = dsempcheck.Tables[0].Rows[j]["FEmplNo"].ToString() }) + "' style= 'cursor:hand;'><li>");
                            strdept.Append(dsempcheck.Tables[0].Rows[j]["FEmpName"].ToString());
                            strdept.Append("</li></a>");
                        }
                        strdept.Append("</ul></div></td></tr>");
                        strdept.Append("</table>");
                    }
                }
            }

            ViewData["strdept"] = strdept.ToString();
            string empName = weekPlanBll.GetempName(empNo);
            ViewData["empNo"] = empNo;
            ViewData["empName"] = empName;

            DateTime beginDate = DateTime.Parse(ViewData["wk"].ToString());

            DataSet dsplantext = weekPlanBll.GetPlanText(beginDate.ToString("yyyy-MM-dd"), empNo);
            StringBuilder textStr = new StringBuilder();
            textStr.Append("<tr><td><strong>" +
                DateTime.Parse(ViewData["wk"].ToString()).ToString("yyyy.MM.dd")
                + "-" +
                DateTime.Parse(ViewData["wk1"].ToString()).ToString("yyyy.MM.dd")
                + "计划任务:</strong></td></tr>");
            if (dsplantext.Tables[0].Rows.Count > 0)
            {
                textStr.Append("<tr><td style='line-height:20px'>" + dsplantext.Tables[0].Rows[0]["FContent"].ToString() + "</td></tr>");
                textStr.Append("<tr><td style='text-align: right;padding-right: 15px;'><span class='rzhui'><strong>");

                textStr.Append("上报:</strong>" + DateTime.Parse(dsplantext.Tables[0].Rows[0]["FInsDate"].ToString()).ToString("yyyy.MM.dd"));

                if (dsplantext.Tables[0].Rows[0]["FCheckDate"].ToString() == "" || dsplantext.Tables[0].Rows[0]["FCheckDate"].ToString() == null)
                {
                    textStr.Append("&nbsp;<font color='red'>未审核</font>");
                }
                else
                {
                    textStr.Append("&nbsp;<strong>审核:</strong>" + DateTime.Parse(dsplantext.Tables[0].Rows[0]["FCheckDate"].ToString()).ToString("yyyy.MM.dd"));
                }
                textStr.Append("</span>");
                textStr.Append("</td></tr>");
            }

            else
            {
                textStr.Append("<tr><td><span class='rzhui'>未录入</span></td></tr>");
            }
            
            ViewData["textStr"] = textStr;


            BLL.Daily dailyBll = new BLL.Daily();

            StringBuilder dailytext = new StringBuilder();

            for (int i = 0; i < 7; i++)
            {
                DataSet dsallday = dailyBll.GetAllDay(i, gowk);

                ///
                DataSet dshol = dailyBll.GetHol(DateTime.Parse(dsallday.Tables[0].Rows[0]["wk"].ToString()));
                dailytext.Append("<table width='734' cellpadding='0' cellspacing='0' class='tablerz1'  style=\"line-height: 10px; overflow-y: auto;\"><tr><td>" + dsallday.Tables[0].Rows[0]["wk"].ToString() + " </td></tr>");
                if (dshol.Tables[0].Rows.Count > 0)
                {
                    dailytext.Append("<tr><td>");
                    dailytext.Append("<strong>完成情况：</strong>放假");
                    dailytext.Append("</tr></td>");
                }
                else
                {
                    DataSet dsdailytext = dailyBll.GetDailyText(DateTime.Parse(dsallday.Tables[0].Rows[0]["wk"].ToString()).ToString("yyyy-MM-dd"), empNo);
                    if (dsdailytext.Tables[0].Rows.Count > 0)
                    {
                        dailytext.Append("<tr>");
                        dailytext.Append("<td><table width='100%' cellpadding='0' cellspacing='0' class='tablerz1'  style=\" overflow-y: auto;\"><tr><td><strong>完成情况：</strong></td></tr>");
                        if (dsdailytext.Tables[0].Rows[0]["FContent"].ToString() == "" || dsdailytext.Tables[0].Rows[0]["FContent"].ToString() == null)
                        {
                            dailytext.Append("<tr><td>未登记</td></tr>");
                        }
                        else
                        {
                            dailytext.Append("<tr><td>" + dsdailytext.Tables[0].Rows[0]["FContent"].ToString() + "</td></tr>");
                            dailytext.Append("<tr><td style=\"text-align:right; overflow-y: auto;\"><span class='rzhui'>" + DateTime.Parse(dsdailytext.Tables[0].Rows[0]["FInsDate"].ToString()).ToString("yyyy-MM-dd") + "</span></td></tr>");
                        }
                        dailytext.Append("</table></td></tr>");
                    }
                    else
                    {
                        dailytext.Append("<tr><td>");
                        dailytext.Append("<strong>完成情况：</strong></td></tr>");
                        dailytext.Append("<tr><td>未登记");
                        dailytext.Append("</td></tr>");
                    }
                }
                dailytext.Append("</table>");

                DataSet dsleave = dailyBll.GetLeave(DateTime.Parse(dsallday.Tables[0].Rows[0]["wk"].ToString()).ToString("yyyy-MM-dd"), empNo);
                if (dsleave.Tables[0].Rows.Count > 0)
                {
                    dailytext.Append("<table width='734' cellpadding='0' cellspacing='0' class='tablerz1'>");
                    DataSet dsleavererson = dailyBll.GetLeaveReason(DateTime.Parse(dsallday.Tables[0].Rows[0]["wk"].ToString()).ToString("yyyy-MM-dd"), empNo);
                    if (dsleavererson.Tables[0].Rows.Count > 0)
                    {
                        for (int j = 0; j < dsleavererson.Tables[0].Rows.Count; j++)
                        {
                            dailytext.Append("<tr><td>" + dsleavererson.Tables[0].Rows[j]["FLeaveReasonName"].ToString() + "：");
                            dailytext.Append(dsleavererson.Tables[0].Rows[j]["FReason"].ToString());
                            dailytext.Append("<font color='999999'>（");
                            dailytext.Append(DateTime.Parse(dsleavererson.Tables[0].Rows[j]["FBeginDate"].ToString()).ToString("yyyy.MM.dd HH:mm") + "-");
                            dailytext.Append(DateTime.Parse(dsleavererson.Tables[0].Rows[j]["FEndDate"].ToString()).ToString("yyyy.MM.dd HH:mm"));
                            dailytext.Append("）</font><br /></td></tr>");
                        }
                    }
                    dailytext.Append("</table>");

                }
            }
            ViewData["dailytext"] = dailytext;
            ViewData["mode"] = mode;

            return View();
        }

    }
}
